package controller

import (
	"cloud-storage/global"
	"cloud-storage/model/mysql"
	"cloud-storage/utils/response"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

//文件分类

// ImageFiles 图片文件
func ImageFiles(c *gin.Context) {
	phone := global.GetPhone(c)
	user, err := mysql.GetUserInfo(phone)
	if err != nil {
		zap.L().Error("mysql.GetUserInfo() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeSelectOperationFail)
		return
	}

	//获取用户文件使用明细数量
	fileDetailUse := mysql.GetFileDetailUser(user.FileStoreId)
	//获取图像类型文件
	imgFiles, err := mysql.GetTypeFile(2, user.FileStoreId)
	if err != nil {
		zap.L().Error("mysql.GetTypeFile() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeSelectOperationFail)
		return
	}
	response.ResponseSuccess(c, gin.H{
		"user":          user,
		"fileDetailUse": fileDetailUse,
		"imgFiles":      imgFiles,
		"imgCount":      len(imgFiles),
		"currImg":       "active",
		"currClass":     "active",
	})
}

// MusicFiles 音乐文件
func MusicFiles(c *gin.Context) {
	phone := global.GetPhone(c)
	user, err := mysql.GetUserInfo(phone)
	if err != nil {
		zap.L().Error("mysql.GetUserInfo() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeSelectOperationFail)
		return
	}

	//获取用户文件使用明细数量
	fileDetailUse := mysql.GetFileDetailUser(user.FileStoreId)
	//获取图像类型文件
	musicFiles, err := mysql.GetTypeFile(4, user.FileStoreId)
	if err != nil {
		zap.L().Error("mysql.GetTypeFile() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeSelectOperationFail)
		return
	}
	response.ResponseSuccess(c, gin.H{
		"user":          user,
		"fileDetailUse": fileDetailUse,
		"musicFiles":    musicFiles,
		"musicCount":    len(musicFiles),
		"currMusic":     "active",
		"currClass":     "active",
	})
}

// VideoFiles 视频文件
func VideoFiles(c *gin.Context) {
	phone := global.GetPhone(c)
	user, err := mysql.GetUserInfo(phone)
	if err != nil {
		zap.L().Error("mysql.GetUserInfo() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeSelectOperationFail)
		return
	}

	//获取用户文件使用明细数量
	fileDetailUse := mysql.GetFileDetailUser(user.FileStoreId)
	//获取图像类型文件
	videoFiles, err := mysql.GetTypeFile(3, user.FileStoreId)
	if err != nil {
		zap.L().Error("mysql.GetTypeFile() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeSelectOperationFail)
		return
	}
	response.ResponseSuccess(c, gin.H{
		"user":          user,
		"fileDetailUse": fileDetailUse,
		"videoFiles":    videoFiles,
		"videoCount":    len(videoFiles),
		"currVideo":     "active",
		"currClass":     "active",
	})
}

// DocFiles 文本文件
func DocFiles(c *gin.Context) {
	phone := global.GetPhone(c)
	user, err := mysql.GetUserInfo(phone)
	if err != nil {
		zap.L().Error("mysql.GetUserInfo() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeSelectOperationFail)
		return
	}

	//获取用户文件使用明细数量
	fileDetailUse := mysql.GetFileDetailUser(user.FileStoreId)
	//获取图像类型文件
	docFiles, err := mysql.GetTypeFile(1, user.FileStoreId)
	if err != nil {
		zap.L().Error("mysql.GetTypeFile() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeSelectOperationFail)
		return
	}
	response.ResponseSuccess(c, gin.H{
		"user":          user,
		"fileDetailUse": fileDetailUse,
		"docFiles":      docFiles,
		"docCount":      len(docFiles),
		"currDoc":       "active",
		"currClass":     "active",
	})
}

// OtherFiles 其他文件
func OtherFiles(c *gin.Context) {
	phone := global.GetPhone(c)
	user, err := mysql.GetUserInfo(phone)
	if err != nil {
		zap.L().Error("mysql.GetUserInfo() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeSelectOperationFail)
		return
	}

	//获取用户文件使用明细数量
	fileDetailUse := mysql.GetFileDetailUser(user.FileStoreId)
	//获取图像类型文件
	otherFiles, err := mysql.GetTypeFile(1, user.FileStoreId)
	if err != nil {
		zap.L().Error("mysql.GetTypeFile() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeSelectOperationFail)
		return
	}
	response.ResponseSuccess(c, gin.H{
		"user":          user,
		"fileDetailUse": fileDetailUse,
		"otherFiles":    otherFiles,
		"otherCount":    len(otherFiles),
		"currOther":     "active",
		"currClass":     "active",
	})
}
